package Java_API;

import java.util.HashMap;
import java.util.HashSet;

public class Leetcode1817 {
    public int[] findingUsersActiveMinutes(int[][] logs, int k) {
        int[] res = new int[k];
        if(logs == null || logs.length == 0 || logs[0].length == 0){
            return res;
        }
        HashMap<Integer, HashSet<Integer>> map = new HashMap<>();

        for(int i=0; i<logs.length; i++){
            int key = logs[i][0];
            int value = logs[i][1];

            HashSet<Integer> tmp = map.getOrDefault(key, new HashSet<Integer>());
            tmp.add(value);
            map.put(key, tmp);
        }

        //第二种:通过Map.values()遍历所有的value但是不能遍历key
        for(HashSet<Integer> s:map.values()){
            if(s!=null){
                res[s.size() - 1] ++;
            }
        }
        return res;
    }
}
